import React from 'react';
import NotBranchDisabledButton from '../notBranchDisabledButton';
import { Balloon, Button } from '@teamix/ui';
import intl from '../../../../../../../../../../locale';

export default class WebIdeBtn extends React.Component {
  render() {
    const { ipSetting, project_clone_download, inMoreText, ...others } = this.props;
    if (!ipSetting) {
      return null;
    }
    if (ipSetting.ip_whitelist_enabled && ipSetting.scope === 'all') {
      others.onClick = (e) => {
        e.stopPropagation();
        e.preventDefault();
      };
      const style = {
        cursor: 'not-allowed',
        color: '#fff',
        background: '#e8e8e8',
        position: 'absolute',
        left: 0,
        padding: '0 8px',
        width: '100%',
        borderRadius: '4px',
      };
      return inMoreText ? (
        <Balloon.Tooltip
          align="t"
          trigger={<div {...others} style={style} />}
          text={intl.get({
            id: 'code-assets.components.webIdeBtn.TheEnterpriseHasEnabledIp',
            defaultMessage: '企业已启用 IP 白名单严格管控，暂不支持使用 WebIDE',
          })}
        />
      ) : (
        <Balloon.Tooltip
          align="t"
          trigger={<Button disabled {...others} />}
          text={intl.get({
            id: 'code-assets.components.webIdeBtn.TheEnterpriseHasEnabledIp',
            defaultMessage: '企业已启用 IP 白名单严格管控，暂不支持使用 WebIDE',
          })}
        />
      );
    } else if (
      project_clone_download?.httpCloneLimit?.state === 'disable' &&
      project_clone_download?.sshCloneLimit?.state === 'disable'
    ) {
      others.onClick = (e) => {
        e.stopPropagation();
        e.preventDefault();
      };
      const style = {
        cursor: 'not-allowed',
        color: '#fff',
        background: '#e8e8e8',
        position: 'absolute',
        left: 0,
        padding: '0 8px',
        width: '100%',
        borderRadius: '4px',
      };
      return inMoreText ? (
        <Balloon.Tooltip
          align="t"
          trigger={<div {...others} style={style} />}
          text={'已启用仓库克隆下载控制，暂不支持使用 WebIDE，请联系管理员处理'}
        />
      ) : (
        <Balloon.Tooltip
          align="t"
          trigger={<Button disabled {...others} />}
          text={'已启用仓库克隆下载控制，暂不支持使用 WebIDE，请联系管理员处理'}
        />
      );
    }
    return <NotBranchDisabledButton {...others} inMoreText={inMoreText} />;
  }
}
